package com.ironmaking.Controller;

import com.ironmaking.Handler.Security.Security;
import com.ironmaking.Service.impl.YieldRateService;
import com.ironmaking.Vo.params.YieldTableParams.UploadingYieldTableParams;
import com.ironmaking.Vo.params.YieldTableParams.YieldTableDataParams;
import com.ironmaking.Vo.results.ActionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "/yield", tags = "成材率相关接口")
@RequestMapping("/yield")
public class YieldRateController {

    @Autowired
    private YieldRateService yieldRateService;

    @PostMapping("/getYieldTable")
    @ApiOperation(value = "获取成材率单表信息", httpMethod = "POST")
    @Security
    public ActionResult getYieldTable(@RequestHeader("Authorization") String token, @RequestBody YieldTableDataParams yieldTableDataParams){
        Object result = yieldRateService.getYieldTableByYid(yieldTableDataParams.getYid(), yieldTableDataParams.getPageParams().getPage(), yieldTableDataParams.getPageParams().getSize());
        if (result == null)
            return ActionResult.fail(401,"未找到对应数据");
        return ActionResult.success(result);
    }

    @PostMapping("/uploadingYieldTable")
    @ApiOperation(value = "上传成材率表格", httpMethod = "POST")
    @Security
    public ActionResult uploadingYieldTable(@RequestHeader("Authorization") String token, @RequestBody UploadingYieldTableParams uploadingYieldTableParams){
        int result = yieldRateService.uploadingIngotTable(uploadingYieldTableParams.getUploadingUserId(),uploadingYieldTableParams.getTableName(),uploadingYieldTableParams.getYieldRateTable());
        if (result==-1 )
            return ActionResult.fail(401,"数据上传失败");
        return ActionResult.success(result);
    }

}
